/*日历*/
function myformatter(date) {
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    var d = date.getDate();
    return y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d);
}

function myparser(s) {
    if (!s) return new Date();
    var ss = (s.split('-'));
    var y = parseInt(ss[0], 10);
    var m = parseInt(ss[1], 10);
    var d = parseInt(ss[2], 10);
    if (!isNaN(y) && !isNaN(m) && !isNaN(d)) {
        return new Date(y, m - 1, d);
    } else {
        return new Date();
    }
}


function listIsEmpty(list) {
    if (list == null || list.length == 0) {
        return true;
    }
    return false;
}

/**
 * 时间格式化
 * @param value
 * @returns {string}
 */
function dateFormatter(value) {
    if (value) {
        value = value + '+8'
    }
    var date = new Date(value);
    var year = date.getFullYear().toString();
    var month = (date.getMonth() + 1);
    var day = date.getDate().toString();
    var hour = date.getHours().toString();
    var minutes = date.getMinutes().toString();
    var seconds = date.getSeconds().toString();
    if (month < 10) {
        month = "0" + month;
    }
    if (day < 10) {
        day = "0" + day;
    }
    if (hour < 10) {
        hour = "0" + hour;
    }
    if (minutes < 10) {
        minutes = "0" + minutes;
    }
    if (seconds < 10) {
        seconds = "0" + seconds;
    }
    return year + "-" + month + "-" + day + " " + hour + ":" + minutes + ":" + seconds;
}


/**
 * 日期格式化
 * @param value
 * @returns {string}
 */
function dateFormatter1(value) {
    if (value) {
        value = value + '+8'
    }
    var date = new Date(value);
    var year = date.getFullYear().toString();
    var month = (date.getMonth() + 1);
    var day = date.getDate().toString();

    if (month < 10) {
        month = "0" + month;
    }
    if (day < 10) {
        day = "0" + day;
    }

    return year + "-" + month + "-" + day;
}

$.fn.parseForm = function () {
    let serializeObj = {};
    let array = this.serializeArray();
    let str = this.serialize();
    $(array).each(function () {
        if (serializeObj[this.name]) {
            if ($.isArray(serializeObj[this.name])) {
                serializeObj[this.name].push(this.value);
            } else {
                serializeObj[this.name] = [serializeObj[this.name], this.value];
            }
        } else {
            serializeObj[this.name] = this.value;
        }
    });
    return serializeObj;
};


function groupBy(array, f) {
    const groups = {};
    array.forEach(function (o) { //注意这里必须是forEach 大写
        const group = f(o);
        groups[group] = groups[group] || [];
        groups[group].push(o);
    });
    return groups
    /*return Object.keys(groups).map(function (group) {
        return groups[group];
    });*/
}

function spiltGroup(obj) {
    /*转置  https://www.programminghunter.com/article/3666648814/*/
    var arr = []
    var arr2 = []
    var arr3 = []
    for (var key in obj) {
        arr.push(obj[key])
    }
    arr.forEach(function (item) {
        arr2.push(item.length)
    })
    var maxLen = Math.max(...arr2)
    for (var i = 0; i < maxLen; i++) {
        arr3.push(undefined)
    }
    if (arr[0].length < maxLen) {
        arr[0] = arr[0].concat(arr3).slice(0, maxLen)
    }
    var result = arr[0].map(function (col, i) {
        return arr.map(function (row) {
            return row[i]
        })
    });
    result = result.map(function (item) {
        return item.filter(function (i) {
            return i != undefined
        })
    })
    return result
}


function linkStockDetail(val, row, index) {
    //股票详情
    market = 'sh'
    stock_code = row.stock_code
    if (stock_code.indexOf('00') == 0 || stock_code.indexOf('30') == 0) {
        market = 'sz'
    }
    var href_url = 'http://quote.eastmoney.com/' + market + row.stock_code + '.html'
    return '<a href="' + href_url + '" target="_blank">' + row.stock_name + '</a>';
}